﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.VisualStyles;

namespace WinFormCenter.common{
    internal static class Tip {

        public static void Tips(string msg) {
            using var tip = new InfoAutoClose(msg,null);
            tip.ShowDialog();
        }
        public static void Tips(string msg, InfoAutoClose.TipsHandler tipsHandler) {
            using var tip = new InfoAutoClose(msg,tipsHandler);
            
            tip.ShowDialog();
           
        }
        
       
        public static void Info(string msg) {
            MessageBox.Show(msg);
        }

        public static void Confirm(string msg) {
            //MessageBox.Show($"{groupBox_Industry.Text}空,是否新增?", "提示12"
            //, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            MessageBox.Show(msg);
        }

        internal static void Error(string msg) {
            MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        /**
*   // 展示Asterisk图标
   MessageBox.Show("这是 Asterisk 图标", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
   // 展示Error图标
   MessageBox.Show("这是 Error 图标", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Error);
   // 展示Exclamation图标
   MessageBox.Show("这是 Exclamation 图标", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
   // 展示Hand图标（等同于Error）
   MessageBox.Show("这是 Hand 图标（等同于Error）", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Hand);
   // 展示Information图标（等同于Asterisk）
   MessageBox.Show("这是 Information 图标（等同于Asterisk）", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Information);
   // 展示None图标（无图标）
   MessageBox.Show("这是 None 图标（无图标）", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.None);
   // 展示Question图标
   MessageBox.Show("这是 Question 图标", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Question);
   // 展示Stop图标（等同于Error）
   MessageBox.Show("这是 Stop 图标（等同于Error）", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Stop);
   // 展示Warning图标（等同于Exclamation）
   MessageBox.Show("这是 Warning 图标（等同于Exclamation）", "图标示例", MessageBoxButtons.OK, MessageBoxIcon.Warning);
*/

        //1.5秒后自动关闭的提示窗口
        public class InfoAutoClose : Form {
            private readonly System.Windows.Forms.Timer timer;
            public InfoAutoClose(string msg, TipsHandler? tipsHandler) {
                //FormBorderStyle = FormBorderStyle.;
                ControlBox = false;

                //AutoSize = true;
                //AutoSizeMode = AutoSizeMode.GrowAndShrink;
                //MinimumSize = new Size(100,100);
                var box = new TextBox {
                    Text = msg,
                    Multiline = true,//允许多行
                    ReadOnly = true,//只读
                    TabStop = false,//禁止聚焦
                    WordWrap = true,//自动换行
                    Dock = DockStyle.Fill,
                    TextAlign=HorizontalAlignment.Center,//水平居中
                    Width = 400,

                };
                var line=msg.Length / 12;
                if (line < 3) {
                    line = 3;
                }
                Size = new Size(box.Width, line * 40);
                Controls.Add(box);

                TipsStart += tipsHandler;
                TipsStart?.Invoke(this, new TipsEventArgs(msg));

                timer = new System.Windows.Forms.Timer { Interval = 1500 };
                timer.Tick += (s, e) => { Close(); timer.Dispose(); };
                timer.Start();
            }
            public event TipsHandler? TipsStart;
            public delegate void TipsHandler(InfoAutoClose sender, TipsEventArgs e); 
        }
        public class TipsEventArgs(string msg) {
           public string Msg { set; get; } = msg;
        }

    }
   
}
